home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows5 / winsrc17.zip / WINDOS.C < prev    next >
C/C++ Source or Header  |  1992-02-01  |  36KB  |  1,271 lines

  1. /*
  2.     Routines which simulate DOS functions in the existing
  3.     Fractint for DOS
  4. */
  5.  
  6. #include "windows.h"
  7. #include "drivinit.h"
  8. #include "fractint.h"
  9. #include "winfract.h"
  10. #include <string.h>
  11. #include <time.h>
  12. #include <stdio.h>
  13.  
  14. extern unsigned char FullPathName[];
  15. extern int FileFormat;
  16.  
  17. int save_system;       /* tag identifying Fractint for Windows */
  18. int save_release;       /* tag identifying version number */
  19. int win_release = 1700;    /* tag identifying version number */
  20. char win_comment[] =       /* "About..." comment */
  21. /*     {" "};              /*  publicly-released version */
  22.   {"Test Version - Not for Release"};   /* interim test versions */
  23.  
  24. extern BOOL bTrack;             /* TRUE if user is selecting a region */
  25. extern BOOL zoomflag;             /* TRUE is a zoom-box selected */
  26.  
  27. extern HWND hwnd;             /* handle to main window */
  28. extern HANDLE hInst;
  29.  
  30. extern char szHelpFileName[];         /* Help file name*/
  31.  
  32. extern int xdots, ydots, colors, maxiter;
  33. extern int xposition, yposition, win_xoffset, win_yoffset, xpagesize, ypagesize;
  34. extern int win_xdots, win_ydots;
  35.  
  36. extern int last_written_y;         /* last line written */
  37. extern int screen_to_be_cleared;     /* clear screen flag */
  38.  
  39. extern int time_to_act;          /* time to take some action? */
  40. extern int time_to_restart;         /* time to restart?  */
  41. extern int time_to_quit;         /* time to quit? */
  42. extern int time_to_reinit;         /* time to reinitialize? */
  43. extern int time_to_load;         /* time to load? (DECODE) */
  44. extern int time_to_save;         /* time to save? (ENCODE) */
  45. extern int time_to_print;         /* time to print? (PRINTER) */
  46. extern int time_to_cycle;         /* time to begin color-cycling? */
  47.  
  48. extern unsigned char dacbox[256][3];
  49.  
  50. extern BOOL win_systempaletteused;    /* flag system palette set */
  51.  
  52. extern unsigned char far temp_array[];     /* temporary spot for Encoder rtns */
  53.  
  54. extern HANDLE hpixels;            /* handle to the DIB pixels */
  55. extern unsigned char huge *pixels;   /* the device-independent bitmap pixels */
  56. int pixels_per_byte;             /* pixels/byte in the pixmap */
  57. long pixels_per_bytem1;          /* pixels / byte - 1 (for ANDing) */
  58. int pixelshift_per_byte;         /* 0, 1, 2, or 3 */
  59. int bytes_per_pixelline;         /* pixels/line / pixels/byte */
  60. long win_bitmapsize;             /* bitmap size, in bytes */
  61.  
  62. extern int win_overlay3d;
  63. extern int win_display3d;
  64.  
  65. extern void center_window(HWND,int,int);
  66.  
  67. /****************************************************************************
  68.  
  69.     FUNCTION: keypressed(), getakey()
  70.  
  71.     PURPOSE:
  72.      keypressed()
  73.           Checks for, and processes, messages.
  74.           Returns -1 if it's time to wrap up and go home.
  75.           Returns 0 otherwise.
  76.     getakey()
  77.           same, but doesn't return until it's time to.
  78.  
  79.  
  80. ****************************************************************************/
  81.  
  82. BOOL dont_wait_for_a_key = TRUE;
  83.  
  84. #ifdef __BORLANDC__
  85.  
  86. /* Too many functions defaulting to a type 'int' return that should be
  87.    a type 'void'.  I'll just get rid of the warning message for this file
  88.    only.  MCP 8-6-91 */
  89.  
  90.    #pragma warn -rvl
  91.  
  92.    int LPTNumber;
  93.    int stackavail() { return(10240 + (signed int)_SP); }
  94. #else
  95.    int _FAR_ _cdecl printf() {}
  96.    int _bios_serialcom(){}
  97. #endif
  98.  
  99.  
  100.  
  101.  
  102. int getakey()
  103. {
  104. int i;
  105.  
  106. dont_wait_for_a_key = FALSE;
  107. i = keypressed();
  108. dont_wait_for_a_key = TRUE;
  109. zoomflag = FALSE;
  110. return(i);
  111.  
  112. }
  113.  
  114. int keypressed()
  115. {
  116. MSG msg;
  117.  
  118. if (dont_wait_for_a_key)
  119.     if (PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) == 0) {
  120.     time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  121.         time_to_load+time_to_save+time_to_print+time_to_cycle;
  122.     /* bail out if nothing is happening */
  123.     return(time_to_act);
  124.     }
  125.  
  126. while (GetMessage(&msg, NULL, NULL, NULL)) {
  127.  
  128.     TranslateMessage(&msg);
  129.     DispatchMessage(&msg);
  130.  
  131.     CheckMathTools();
  132.     if (!bTrack) {          /* don't do this if mouse-button is down */
  133.     time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  134.         time_to_load+time_to_save+time_to_print+time_to_cycle;
  135.     if (dont_wait_for_a_key || time_to_act)
  136.         return(time_to_act);
  137.     }
  138.  
  139.     }
  140.  
  141. if (!dont_wait_for_a_key)
  142.     time_to_quit = 1;
  143.  
  144.     /* bail out if nothing is happening */
  145.     time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  146.     time_to_load+time_to_save+time_to_print+time_to_cycle;
  147.     return(time_to_act);
  148.  
  149. }
  150.  
  151. /****************************************************************************
  152.  
  153.     FUNCTION: putcolor(int x, int y, int color), getcolor(int x, int y)
  154.  
  155.     PURPOSE:
  156.     putcolor:
  157.        sets the "color" value of the pixel at location x,y
  158.        (actually, a palette value)
  159.     getcolor:
  160.        returns the "color" value of the pixel at location x,y
  161.        (actually, a palette value)
  162.  
  163. ****************************************************************************/
  164.  
  165. extern int debug_fastupdate;
  166.  
  167. time_t last_time;
  168. time_t update_time;
  169. long minimum_update;
  170. long pixelsout;
  171. int top_changed, bottom_changed;
  172.  
  173. /* Made global, MCP 6-16-91 */
  174. unsigned char win_andmask[8];
  175. unsigned char win_notmask[8];
  176. unsigned char win_bitshift[8];
  177.  
  178. void putcolor(int x, int y, int color)
  179. {
  180. RECT tempRect;             /* temporary rectangle structure */
  181. long i;
  182. int temp_top_changed, temp_bottom_changed;
  183. time_t this_time;
  184.  
  185. last_written_y = y;
  186. if (y < top_changed) top_changed = y;
  187. if (y > bottom_changed) bottom_changed = y;
  188.  
  189. i = win_ydots-1-y;
  190. i = (i * win_xdots) + x;
  191.  
  192. if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
  193.     if (pixelshift_per_byte == 0) {
  194.       pixels[i] = color % colors;
  195.       }
  196.      else {
  197.       unsigned int j;
  198.       j = i & pixels_per_bytem1;
  199.       i = i >> pixelshift_per_byte;
  200.       pixels[i] = (pixels[i] & win_notmask[j]) +
  201.           (((unsigned char)(color % colors)) << win_bitshift[j]);
  202.       }
  203.  
  204.      /* check the time every nnn pixels */
  205.      if (debug_fastupdate || ++pixelsout > 100) {
  206.       pixelsout = 0;
  207.       this_time = time(NULL);
  208.       /* time to update the screen? */
  209.       if (debug_fastupdate || (this_time - last_time) > update_time ||
  210.           (minimum_update*(this_time-last_time)) > (bottom_changed-top_changed)) {
  211.           temp_top_changed = top_changed - win_yoffset;
  212.           temp_bottom_changed = bottom_changed - win_yoffset;
  213.           if (!(temp_top_changed >= ypagesize || temp_bottom_changed < 0)) {
  214.           if (temp_top_changed < 0) temp_top_changed = 0;
  215.           if (temp_bottom_changed < 0) temp_bottom_changed = 0;
  216.           tempRect.top = temp_top_changed;
  217.           tempRect.bottom = temp_bottom_changed+1;
  218.           tempRect.left = 0;
  219.           tempRect.right = xdots;
  220.           InvalidateRect(hwnd, &tempRect, FALSE);
  221.           keypressed();    /* force a look-see at the screen */
  222.           }
  223.           last_time = this_time;
  224.           top_changed = win_ydots;
  225.           bottom_changed = 0;
  226.           }
  227.       }
  228.      }
  229.  
  230. }
  231.  
  232. int getcolor(int x, int y)
  233. {
  234. long i;
  235.  
  236. i = win_ydots-1-y;
  237. i = (i * win_xdots) + x;
  238.  
  239. if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
  240.     if (pixelshift_per_byte == 0) {
  241.       return(pixels[i]);
  242.       }
  243.      else {
  244.       unsigned int j;
  245.       j = i & pixels_per_bytem1;
  246.       i = i >> pixelshift_per_byte;
  247.       return((int)((pixels[i] & win_andmask[j]) >> win_bitshift[j]));
  248.       }
  249.      }
  250. else
  251.      return(0);
  252. }
  253.  
  254. int put_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
  255. {
  256. int i, len;
  257. long startloc;
  258.  
  259. len = rightpt - leftpt;
  260. if (rightpt >= xdots) len = xdots - 1 - leftpt;
  261. startloc = win_ydots-1-rownum;
  262. startloc = (startloc * win_xdots) + leftpt;
  263.  
  264. if (rownum < 0 || rownum >= ydots || leftpt < 0) {
  265.     return(0);
  266.     }
  267.  
  268. if (pixelshift_per_byte == 0) {
  269.     for (i = 0; i <= len; i++)
  270.     pixels[startloc+i] = localvalues[i];
  271.     }
  272. else {
  273.     unsigned int j;
  274.     long k;
  275.     for (i = 0; i <= len; i++) {
  276.     k = startloc + i;
  277.     j = k & pixels_per_bytem1;
  278.     k = k >> pixelshift_per_byte;
  279.     pixels[k] = (pixels[k] & win_notmask[j]) +
  280.         (((unsigned char)(localvalues[i] % colors)) << win_bitshift[j]);
  281.     }
  282.     }
  283. pixelsout += len;
  284. putcolor(leftpt, rownum, localvalues[0]);
  285. }
  286.  
  287. int get_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
  288. {
  289. int i, len;
  290. long startloc;
  291.  
  292. len = rightpt - leftpt;
  293. if (rightpt >= xdots) len = xdots - 1 - leftpt;
  294. startloc = win_ydots-1-rownum;
  295. startloc = (startloc * win_xdots) + leftpt;
  296.  
  297. if (rownum < 0 || rownum >= ydots || leftpt < 0 || rightpt >= xdots) {
  298.     for (i = 0; i <= len; i++)
  299.     localvalues[i] = 0;
  300.     return(0);
  301.     }
  302.  
  303. if (pixelshift_per_byte == 0) {
  304.     for (i = 0; i <= len; i++)
  305.     localvalues[i] = pixels[startloc+i];
  306.     }
  307. else {
  308.     unsigned int j;
  309.     long k;
  310.     for (i = 0; i <= len; i++) {
  311.     k = startloc + i;
  312.     j = k & pixels_per_bytem1;
  313.     k = k >> pixelshift_per_byte;
  314.     localvalues[i] = (pixels[k] & win_andmask[j]) >> win_bitshift[j];
  315.     }
  316.     }
  317. }
  318.  
  319. extern int rowcount;
  320.  
  321. int out_line(unsigned char *localvalues, int numberofdots)
  322. {
  323.     put_line(rowcount++, 0, numberofdots, localvalues);
  324. }
  325.  
  326. extern LPBITMAPINFO pDibInfo;        /* pointer to the DIB info */
  327.  
  328. int clear_screen(int forceclear)
  329. {
  330. long numdots;
  331. int i;
  332.  
  333. win_xdots = (xdots+3) & 0xfffc;
  334. win_ydots = ydots;
  335. pixelshift_per_byte = 0;
  336. pixels_per_byte   = 1;
  337. pixels_per_bytem1 = 0;
  338. if (colors == 16) {
  339.     win_xdots = (xdots+7) & 0xfff8;
  340.     pixelshift_per_byte = 1;
  341.     pixels_per_byte = 2;
  342.     pixels_per_bytem1 = 1;
  343.     win_andmask[0] = 0xf0;  win_notmask[0] = 0x0f; win_bitshift[0] = 4;
  344.     win_andmask[1] = 0x0f;  win_notmask[1] = 0xf0; win_bitshift[1] = 0;
  345.     }
  346. if (colors == 2) {
  347.     win_xdots = (xdots+31) & 0xffe0;
  348.     pixelshift_per_byte = 3;
  349.     pixels_per_byte = 8;
  350.     pixels_per_bytem1 = 7;
  351.     win_andmask[0] = 0x80;  win_notmask[0] = 0x7f; win_bitshift[0] = 7;
  352.     for (i = 1; i < 8; i++) {
  353.     win_andmask[i] = win_andmask[i-1] >> 1;
  354.     win_notmask[i] = (win_notmask[i-1] >> 1) + 0x80;
  355.     win_bitshift[i] = win_bitshift[i-1] - 1;
  356.     }
  357.     }
  358.  
  359. numdots = (long)win_xdots * (long) win_ydots;
  360. update_time = 2;
  361. if (numdots > 200000L) update_time = 4;
  362. if (numdots > 400000L) update_time = 8;
  363. last_time = time(NULL) - update_time + 1;
  364. minimum_update = 7500/xdots;    /* assume 75,000 dots/sec drawing speed */
  365.  
  366. last_written_y = -1;
  367. pixelsout = 0;
  368. top_changed = win_ydots;
  369. bottom_changed = 0;
  370.  
  371. bytes_per_pixelline = win_xdots >> pixelshift_per_byte;
  372.  
  373. /* Create the Device-independent Bitmap entries */
  374. pDibInfo->bmiHeader.biWidth  = win_xdots;
  375. pDibInfo->bmiHeader.biHeight = win_ydots;
  376. pDibInfo->bmiHeader.biSizeImage = (DWORD)bytes_per_pixelline * win_ydots;
  377. pDibInfo->bmiHeader.biBitCount = 8 / pixels_per_byte;
  378.  
  379. /* hard to believe, but this is the fast way to clear the pixel map */
  380. if (hpixels) {
  381.      GlobalUnlock(hpixels);
  382.      GlobalFree(hpixels);
  383.      }
  384.  
  385. win_bitmapsize = (numdots >> pixelshift_per_byte)+1;
  386.  
  387. if (!(hpixels = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, win_bitmapsize)))
  388.      return(0);
  389. if (!(pixels = (char huge *)GlobalLock(hpixels))) {
  390.      GlobalFree(hpixels);
  391.      return(0);
  392.      }
  393.  
  394. /* adjust the colors for B&W or default */
  395. if (colors == 2) {
  396.     dacbox[0][0] = dacbox[0][1] = dacbox[0][2] = 0;
  397.     dacbox[1][0] = dacbox[1][1] = dacbox[1][2] = 63;
  398.     spindac(0,1);
  399.     }
  400. else
  401.     restoredac();   /* color palette */
  402.  
  403. screen_to_be_cleared = 1;
  404. InvalidateRect(hwnd, NULL, TRUE);
  405.  
  406. if (forceclear)
  407.     keypressed();        /* force a look-see at the screen */
  408.  
  409. return(1);
  410. }
  411.  
  412. int flush_screen()
  413. {
  414.  
  415. last_written_y = 0;
  416.  
  417. InvalidateRect(hwnd, NULL, FALSE);
  418.  
  419. }
  420.  
  421. /****************************************************************************
  422.  
  423.     FUNCTION: buzzer(int buzzertype)
  424.  
  425.     PURPOSE:
  426.           make some sort of sound (hey, we do what we can)
  427.  
  428. ****************************************************************************/
  429.  
  430. void buzzer(int i)
  431. {
  432.  
  433. MessageBeep(0);
  434.  
  435. }
  436.  
  437. /****************************************************************************
  438.  
  439.     FUNCTION: unsigned char far * farmemalloc(long bytecount)
  440.           void farmemfree(unsigned char * bytepointer)
  441.     PURPOSE:
  442.           allocate and free memory in a manner consistent with
  443.           Fractint for DOS
  444.  
  445. ****************************************************************************/
  446.  
  447. #define MAXFARMEMALLOCS  50        /* max active farmemallocs */
  448. int   farmemallocinit = 0;        /* any memory been allocated yet?   */
  449. HANDLE farmemallochandles[MAXFARMEMALLOCS];            /* handles  */
  450. void far *farmemallocpointers[MAXFARMEMALLOCS]; /* pointers */
  451.  
  452. void far * farmemalloc(long bytecount)
  453. {
  454. int i;
  455. HANDLE temphandle;
  456. unsigned char far *temppointer;
  457.  
  458. if (!farmemallocinit) {     /* never been here yet - initialize */
  459.     farmemallocinit = 1;
  460.     for (i = 0; i < MAXFARMEMALLOCS; i++) {
  461.     farmemallochandles[i] = (HANDLE)0;
  462.     farmemallocpointers[i] = NULL;
  463.     }
  464.     }
  465.  
  466. for (i = 0; i < MAXFARMEMALLOCS; i++)  /* look for a free handle */
  467.     if (farmemallochandles[i] == (HANDLE)0) break;
  468.  
  469. if (i == MAXFARMEMALLOCS)    /* uh-oh - no more handles */
  470.    return(NULL);        /* can't get far memory this way */
  471.  
  472. if (!(temphandle = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, bytecount)))
  473.      return(NULL);        /* can't allocate the memory */
  474. if (!(temppointer = (unsigned char far *)GlobalLock(temphandle))) {
  475.      GlobalFree(temphandle);
  476.      return(NULL);        /* ?? can't lock the memory ?? */
  477.      }
  478.  
  479. farmemallochandles[i] =  temphandle;
  480. farmemallocpointers[i] = temppointer;
  481. return(temppointer);
  482. }
  483.  
  484. void farmemfree(void far *bytepointer)
  485. {
  486. int i;
  487.  
  488. if (bytepointer == (void far *)NULL) return;
  489.  
  490. for (i = 0; i < MAXFARMEMALLOCS; i++)    /* search for a matching pointer */
  491.     if (farmemallocpointers[i] == bytepointer)
  492.      break;
  493. if (i < MAXFARMEMALLOCS) {        /* got one */
  494.     GlobalUnlock(farmemallochandles[i]);
  495.     GlobalFree(farmemallochandles[i]);
  496.     farmemallochandles[i] = (HANDLE)0;
  497.     }
  498.  
  499. }
  500.  
  501. debugmessage(char *msg1, char *msg2)
  502. {
  503. MessageBox (
  504.     GetFocus(),
  505.     msg2,
  506.     msg1,
  507.     MB_ICONASTERISK | MB_OK);
  508.  
  509. }
  510.  
  511. texttempmsg(char *msg1)
  512. {
  513. MessageBox (
  514.     GetFocus(),
  515.     msg1,
  516.     "Encoder",
  517.     MB_ICONASTERISK | MB_OK);
  518. }
  519.  
  520. stopmsg(int flags, unsigned char far *msg1)
  521. {
  522. int result;
  523.  
  524. if (! (flags & 4)) MessageBeep(0);
  525.  
  526. result = IDOK;
  527.  
  528. if (!(flags & 2))
  529.     MessageBox (
  530.     NULL,
  531.     msg1,
  532.     "Fractint for Windows",
  533.     MB_TASKMODAL | MB_ICONASTERISK | MB_OK);
  534. else
  535.     result = MessageBox (
  536.     NULL,
  537.     msg1,
  538.     "Fractint for Windows",
  539.     MB_TASKMODAL | MB_ICONQUESTION | MB_OKCANCEL);
  540.  
  541. if (result == 0 || result == IDOK || result == IDYES)
  542.     return(0);
  543. else
  544.     return(-1);
  545. }
  546.  
  547. extern char readname[];
  548. extern int fileydots, filexdots, filecolors;
  549. extern int     iNumColors;    /* Number of colors supported by device           */
  550. extern int     iRasterCaps;   /* Raster capabilities                   */
  551.  
  552. win_load()
  553. {
  554. int i;
  555.  
  556. time_to_load = 0;
  557.  
  558.     start_wait();
  559.     if ((i = read_overlay()) >= 0 && (!win_display3d ||
  560.     xdots < filexdots || ydots < fileydots)) {
  561.     if (win_display3d) stopmsg(0,
  562.         "3D and Overlay3D file image sizes must be\nat least as large as the display image.\nAltering your display image to match the file.");
  563.     xdots = filexdots;
  564.     ydots = fileydots;
  565.     colors = filecolors;
  566.     if (colors > 16) colors = 256;
  567.     if (colors >  2 && colors < 16) colors = 16;
  568.     if (xdots < 50) xdots = 50;
  569.     if (xdots > 2048) xdots = 2048;
  570.     if (ydots < 50) ydots = 50;
  571.     if (ydots > 2048) ydots = 2048;
  572.     set_win_offset();
  573.     clear_screen(0);
  574.     }
  575.     end_wait();
  576.     return(i);
  577. }
  578.  
  579. win_save()
  580. {
  581.     time_to_save = 0;
  582.     save_system = 1;
  583.     save_release = win_release;
  584.  
  585.     /* MCP 10-27-91 */
  586.     if(FileFormat != ID_BMP)
  587.        savetodisk(readname);
  588.     else
  589.        SaveBitmapFile(hwnd, FullPathName);
  590.     CloseStatusBox();
  591. }
  592.  
  593.  
  594. /********************    Printer logic    *********************/
  595.  
  596. static struct PRINFO { /* dynamic alloc these to avoid eating static space */
  597.     HDC printerDC;        /* printer device context */
  598.     HANDLE hdm;         /* memory handle for next, NULL if none */
  599.     LPDEVMODE dm;        /* devmode block from printer */
  600.     BOOL b_print_abort;     /* abort flag from abort routine */
  601.     HWND h_pabort_dialog;    /* handle for abort window */
  602.     char drivername[41];
  603.     char devname[61];
  604.     char outname[41];
  605.     int cur_orient;        /* current options, saved if dialog ok'd */
  606.     int cur_maxflag;
  607.     float cur_width;
  608.     int width_ok;        /* FALSE if width currently in error */
  609.     float printer_xsize;    /* size of max print area in inches */
  610.     float printer_ysize;
  611.     int printer_xpix;        /* number of pixels across max print area */
  612.     int printer_ypix;
  613.     } far *pr;
  614.  
  615. static int pr_orient  = DMORIENT_LANDSCAPE; /* user selected orientation */
  616. static int pr_maxflag = 1;            /* user selected max size?     */
  617. static float pr_width = 0;            /* user selected width     */
  618.  
  619. static void create_printer_DC()
  620. {
  621.     HDC displayDC;
  622.     float daspect, paspect;
  623.     int printer_xdots, printer_ydots;
  624.     if (pr->printerDC) /* ditch the old one first if present */
  625.     DeleteDC(pr->printerDC);
  626.     if (!pr->dm) /* no DEVMODE, an old driver? */
  627.     pr->printerDC = CreateDC(pr->drivername, pr->devname, pr->outname, NULL);
  628.     else { /* got DEVMODE block so get fancy */
  629.     if ((pr->dm->dmFields & DM_ORIENTATION))
  630.         pr->dm->dmOrientation = pr->cur_orient;
  631.     if ((pr->dm->dmFields & DM_COLOR))
  632.         pr->dm->dmColor = DMCOLOR_COLOR;
  633.     pr->printerDC = CreateDC(pr->drivername, pr->devname, pr->outname, (LPSTR)pr->dm);
  634.     }
  635.     if (pr->printerDC) { /* calculate size of max area on printer */
  636.     displayDC = GetDC(NULL);
  637.     daspect = ((float)xdots / GetDeviceCaps(displayDC,LOGPIXELSX))
  638.         / ((float)ydots / GetDeviceCaps(displayDC,LOGPIXELSY));
  639.     ReleaseDC(NULL,displayDC);
  640.     printer_xdots = GetDeviceCaps(pr->printerDC,HORZRES);
  641.     printer_ydots = GetDeviceCaps(pr->printerDC,VERTRES);
  642.     paspect = ((float)printer_xdots / GetDeviceCaps(pr->printerDC,HORZSIZE))
  643.         / ((float)printer_ydots / GetDeviceCaps(pr->printerDC,VERTSIZE));
  644.     pr->printer_xpix = printer_xdots;
  645.     pr->printer_ypix = (float)printer_xdots / daspect / paspect;
  646.     if (pr->printer_ypix > printer_ydots) {
  647.         pr->printer_xpix = (float)pr->printer_xpix * (float) printer_ydots
  648.                  / (float)pr->printer_ypix;
  649.         if (pr->printer_xpix > printer_xdots)
  650.         pr->printer_xpix = printer_xdots;
  651.         pr->printer_ypix = printer_ydots;
  652.         }
  653.     pr->printer_xsize = (float)pr->printer_xpix
  654.               / GetDeviceCaps(pr->printerDC,LOGPIXELSX);
  655.     pr->printer_ysize = (float)pr->printer_ypix
  656.               / GetDeviceCaps(pr->printerDC,LOGPIXELSY);
  657.     }
  658. }
  659.  
  660. static void show_printsizes(HWND hDlg)
  661. {
  662.     HWND tmphwnd;
  663.     char buf[80];
  664.     sprintf(buf,"(%.2f x %.2f inches)",pr->printer_xsize,pr->printer_ysize);
  665.     SetDlgItemText(hDlg,ID_PRS_MAXSIZ,buf);
  666.     if (pr->cur_width == 0 || pr->cur_width > pr->printer_xsize)
  667.     pr->cur_width = pr->printer_xsize;
  668.     sprintf(buf,"%.2f",pr->cur_width);
  669.     SetDlgItemText(hDlg,ID_PRS_WIDTH,buf);
  670.     tmphwnd = GetDlgItem(hDlg,ID_PRS_WIDTH);
  671.     EnableWindow(tmphwnd,1 ^ pr->cur_maxflag); /* grey if max selected */
  672. }
  673.  
  674. BOOL FAR PASCAL PrintDlg(HWND hDlg, unsigned msg, WORD wParam, LONG lParam)
  675. {
  676.     int i;
  677.     HWND tmphwnd;
  678.     char buf[120];
  679.     float f;
  680.  
  681.     switch (msg) {
  682.  
  683.       case WM_INITDIALOG:
  684.     center_window(hDlg,0,0);
  685.     _fstrcpy((char far *)buf,pr->devname);
  686.     strcat(buf," on ");
  687.     _fstrcat((char far *)buf,pr->outname);
  688.     if (buf[i=strlen(buf)-1] == ':') buf[i] = 0;
  689.     SetDlgItemText(hDlg,ID_PR_DEVICE,buf);
  690.     if (!pr->dm || !(pr->dm->dmFields & DM_ORIENTATION)) {
  691.         i = 1; /* must use portrait */
  692.         tmphwnd = GetDlgItem(hDlg,ID_PRO_LANDS);
  693.         EnableWindow(tmphwnd,0);
  694.         }
  695.     else
  696.         i = (pr->cur_orient == DMORIENT_LANDSCAPE) ? 0 : 1;
  697.     CheckDlgButton(hDlg, ID_PRO_PORTR, i);
  698.     CheckDlgButton(hDlg, ID_PRO_LANDS, i ^ 1);
  699.     CheckDlgButton(hDlg, ID_PRS_MAX,  pr->cur_maxflag);
  700.     CheckDlgButton(hDlg, ID_PRS_CUST, pr->cur_maxflag ^ 1);
  701.     show_printsizes(hDlg); /* show the rest */
  702.     break;
  703.  
  704.       case WM_COMMAND:
  705.     switch (wParam) {
  706.       case IDOK:
  707.         if (pr->cur_maxflag == 0 && !pr->width_ok) {
  708.         MessageBeep(0);
  709.         SetFocus(GetDlgItem(hDlg, ID_PRS_WIDTH));
  710.         break;
  711.         }
  712.         EndDialog(hDlg, 1);
  713.         break;
  714.       case IDCANCEL:
  715.         EndDialog(hDlg, 0);
  716.         break;
  717.       case ID_PRO_PORTR:
  718.       case ID_PRO_LANDS:
  719.         pr->cur_orient = (wParam == ID_PRO_PORTR)
  720.                ? DMORIENT_PORTRAIT : DMORIENT_LANDSCAPE;
  721.         if (pr->cur_width == pr->printer_xsize)
  722.         pr->cur_width = 0; /* force reset to match new size */
  723.         create_printer_DC();   /* new device context for new orient */
  724.         show_printsizes(hDlg); /* display new orientation sizes */
  725.         break;
  726.       case ID_PRS_MAX:
  727.       case ID_PRS_CUST:
  728.         pr->cur_maxflag = (wParam == ID_PRS_MAX) ? 1 : 0;
  729.         show_printsizes(hDlg); /* to set width field grey status */
  730.         break;
  731.       case ID_PRS_WIDTH:
  732.         switch(HIWORD(lParam)) {
  733.           case EN_KILLFOCUS:
  734.         GetDlgItemText(hDlg, ID_PRS_WIDTH, buf, 20);
  735.         i = strlen(buf);
  736.         while (i > 0 && buf[i] == ' ') --i;
  737.         buf[i] = 0;
  738.         if (sscanf(buf,"%f%c",&f) == 1 /* got a float */
  739.           && f <= pr->printer_xsize) { /* not greater than max */
  740.             pr->cur_width = f;
  741.             pr->width_ok = TRUE;
  742.             show_printsizes(hDlg); /* redisplay, formatted */
  743.             }
  744.         else /* entry invalid */
  745.             pr->width_ok = FALSE;
  746.         break;
  747.           default:
  748.         return FALSE;
  749.           }
  750.         break;
  751.       default:
  752.         return FALSE;
  753.       }
  754.     break;
  755.  
  756.       case WM_KEYDOWN:
  757.     switch (wParam) {
  758.       case VK_F1:
  759.         /* F1, shifted F1 bring up the Help Index */
  760.         WinHelp(hwnd,szHelpFileName,HELP_INDEX,0L);
  761.         break;
  762.       default:
  763.         return FALSE;
  764.       }
  765.     break;
  766.  
  767.       default:
  768.     return FALSE;
  769.  
  770.       }
  771.     return TRUE;
  772. }
  773.  
  774. int FAR PASCAL PrintAbortDlg(HWND hWnd, unsigned msg, WORD wParam, LONG lParam)
  775. {
  776.     if (msg == WM_COMMAND) { /* Cancel button (Enter, Esc, Return, Space) */
  777.     pr->b_print_abort = TRUE;
  778.     DestroyWindow(hWnd);
  779.     return (TRUE);
  780.     }
  781.     if (msg == WM_INITDIALOG) {
  782.     center_window(hWnd,0,0);
  783.     SetFocus(hWnd);
  784.     return (TRUE);
  785.     }
  786.     return (FALSE);
  787. }
  788.  
  789. int FAR PASCAL PrintAbort(HDC hPr, int Code)
  790. {
  791.     MSG msg;
  792.     while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
  793.     if (!IsDialogMessage(pr->h_pabort_dialog, &msg)) {
  794.         TranslateMessage(&msg);
  795.         DispatchMessage(&msg);
  796.         }
  797.     return (!pr->b_print_abort); /* return FALSE iff aborted */
  798. }
  799.  
  800. void win_print()
  801. {
  802.     HANDLE hpr;
  803.     int Return;
  804.     int printer_bandable;
  805.     long firstpixel;
  806.     RECT printerRect;
  807.     int more;
  808.     FARPROC lpPrintDlg;
  809.     FARPROC p_print_abort;
  810.     FARPROC p_pabort_dialog;
  811.     int printer_xacross, printer_yacross;
  812.  
  813.     time_to_print = 0;
  814.     hpr = GlobalAlloc(GMEM_FIXED, sizeof(struct PRINFO));
  815.     pr    = (struct PRINFO FAR *)GlobalLock(hpr);
  816.     pr->printerDC = NULL;
  817.     pr->hdm = NULL;
  818.     pr->cur_orient  = pr_orient;
  819.     pr->cur_maxflag = pr_maxflag;
  820.     pr->cur_width   = pr_width;
  821.     pr->width_ok = TRUE;
  822.  
  823.     { /* find the default printer */
  824.     char szPrinter[80];
  825.     char *szDevice, *szDriver, *szOutput;
  826.     int dmsize;
  827.     dmsize = 0;
  828.     GetProfileString ("windows", "device", "", szPrinter, sizeof(szPrinter));
  829.     if ( (szDevice = strtok (szPrinter, "," ))
  830.       && (szDriver = strtok (NULL,    ", "))
  831.       && (szOutput = strtok (NULL,    ", "))) {
  832.     char drivname[40];
  833.     HANDLE hDriver;
  834.     int (FAR PASCAL *p_ExtDeviceMode)(HWND,HANDLE,DEVMODE FAR *,LPSTR,LPSTR,DEVMODE FAR *,LPSTR,WORD);
  835.     _fstrncpy(pr->drivername,(char far *)szDriver,40);
  836.     _fstrncpy(pr->devname,     (char far *)szDevice,60);
  837.     _fstrncpy(pr->outname,     (char far *)szOutput,40);
  838.     pr->drivername[40] = 0;
  839.     pr->devname   [60] = 0;
  840.     pr->outname   [40] = 0;
  841.     strcpy(drivname,szDriver); strcat(drivname,".drv");
  842.     if ((hDriver = LoadLibrary(drivname)) >= 32) { /* else driver not found */
  843.         if ((p_ExtDeviceMode = GetProcAddress(hDriver,"ExtDeviceMode"))
  844.           && (dmsize = (*p_ExtDeviceMode)(NULL,hDriver,NULL,szDevice,szOutput,NULL,NULL,0)) > 0) {
  845.         /* load DEVMODE block */
  846.         pr->hdm = GlobalAlloc(GMEM_FIXED, dmsize);
  847.         pr->dm    = (DEVMODE FAR *)GlobalLock(pr->hdm);
  848.         (*p_ExtDeviceMode)(NULL,hDriver,pr->dm,szDevice,szOutput,NULL,NULL,DM_COPY);
  849.         }
  850.         FreeLibrary(hDriver);
  851.         }
  852.     create_printer_DC();
  853.     }
  854.     if (!pr->printerDC) {
  855.     stopmsg(0,"Can't find the printer!");
  856.     goto win_print_exit;
  857.     }
  858.     }
  859.  
  860.     /* get user options */
  861.     lpPrintDlg = MakeProcInstance((FARPROC) PrintDlg, hInst);
  862.     Return = DialogBox(hInst, "Printoptions", hwnd, lpPrintDlg);
  863.     FreeProcInstance(lpPrintDlg);
  864.     if (Return == 0) /* cancelled */
  865.     goto win_print_exit;
  866.     pr_orient  = pr->cur_orient;    /* not cancelled, remember options */
  867.     pr_maxflag = pr->cur_maxflag;
  868.     pr_width   = pr->cur_width;
  869.  
  870.     start_wait();
  871.  
  872.     printer_bandable =    GetDeviceCaps(pr->printerDC,RASTERCAPS) & RC_BANDING;
  873. /*
  874.     printer_bandable = 0;
  875. */
  876.  
  877.     /* calc print position & size, set up colors */
  878.     firstpixel = win_ydots - ydots;
  879.     firstpixel = firstpixel * bytes_per_pixelline;
  880.     printer_xacross = pr->printer_xpix;
  881.     printer_yacross = pr->printer_ypix;
  882.     if (pr->cur_maxflag == 0 && pr->cur_width != pr->printer_xsize) {
  883.     float f;
  884.     f = pr->cur_width / pr->printer_xsize;
  885.     printer_xacross = f * printer_xacross;
  886.     printer_yacross = f * printer_yacross;
  887.     }
  888.     if (GetDeviceCaps(pr->printerDC,NUMCOLORS) <= 2)
  889.     mono_dib_palette();    /* B&W stripes for B&W printers */
  890.     else
  891.     rgb_dib_palette();
  892.  
  893.     /* set up abort logic */
  894.     pr->b_print_abort = FALSE;
  895.     p_print_abort  = MakeProcInstance(PrintAbort,    hInst);
  896.     p_pabort_dialog = MakeProcInstance(PrintAbortDlg, hInst);
  897.     pr->h_pabort_dialog = CreateDialog(hInst, "Printabort", hwnd, p_pabort_dialog);
  898.     ShowWindow(pr->h_pabort_dialog, SW_NORMAL);
  899.     UpdateWindow(pr->h_pabort_dialog);
  900.     EnableWindow(hwnd, FALSE);
  901.     Return = Escape (pr->printerDC, SETABORTPROC, 0, (LPSTR)p_print_abort, NULL);
  902.     if (Return <= 0 || pr->b_print_abort) goto oops;
  903.  
  904.     /* print */
  905.     Return = Escape (pr->printerDC, STARTDOC, 17, (LPSTR)"Fractint Printout", NULL);
  906.     if (Return <= 0 || pr->b_print_abort) goto oops;
  907.     if (printer_bandable) {
  908.     Return = Escape(pr->printerDC, NEXTBAND, 0, (LPSTR) NULL, (LPSTR) &printerRect);
  909.     if (Return <= 0 || pr->b_print_abort) goto oops;
  910.     }
  911.     more = 1;
  912.     while (more) {
  913.     if (printer_bandable)
  914.         DPtoLP(pr->printerDC, (LPPOINT) &printerRect, 2);
  915.     Return = StretchDIBits(pr->printerDC,
  916.         0, 0,
  917.         printer_xacross, printer_yacross,
  918.         0, 0,
  919.         xdots, ydots,
  920.         (LPSTR)&pixels[firstpixel], (LPBITMAPINFO)pDibInfo,
  921.         DIB_RGB_COLORS, SRCCOPY);
  922.     if (Return <= 0 || pr->b_print_abort) goto oops;
  923.     more = 0;
  924.     if (printer_bandable) {
  925.         Return = Escape(pr->printerDC, NEXTBAND, 0, (LPSTR) NULL, (LPSTR) &printerRect);
  926.         if (Return <= 0 || pr->b_print_abort) goto oops;
  927.         more = ! (IsRectEmpty(&printerRect));
  928.         }
  929.     }
  930.     Return = Escape(pr->printerDC, NEWFRAME, 0, NULL, NULL);
  931.     if (Return <= 0 || pr->b_print_abort) goto oops;
  932.     Return = Escape(pr->printerDC, ENDDOC, 0, NULL, NULL);
  933.  
  934. oops:
  935.     EnableWindow(hwnd, TRUE);
  936.     DestroyWindow(pr->h_pabort_dialog);
  937.     FreeProcInstance(p_print_abort);
  938.     FreeProcInstance(p_pabort_dialog);
  939.     default_dib_palette();   /* replace the palette */
  940.     end_wait();
  941.     if (!pr->b_print_abort) {
  942.     if (Return < 0 && (Return & SP_NOTREPORTED))
  943.         stopmsg(0,"Print failed\nYou probably ran out of memory\nSorry...");
  944.     if (Return == 0)
  945.         stopmsg(0,"Printer driver doesn't have a function we need\nSorry...");
  946.     }
  947.  
  948. win_print_exit: /* cleanup */
  949.     if (pr->printerDC)
  950.     DeleteDC(pr->printerDC);
  951.     if (pr->hdm) {
  952.     GlobalUnlock(pr->hdm); /* DEVMODE */
  953.     GlobalFree(pr->hdm);
  954.     }
  955.     GlobalUnlock(hpr); /* general vars */
  956.     GlobalFree(hpr);
  957.  
  958. }
  959.  
  960.  
  961. extern int win_cycledir, win_cyclerand, win_cyclefreq;
  962.  
  963. extern HANDLE  hPal;       /* Palette Handle */
  964. extern LPLOGPALETTE pLogPal;  /* pointer to the application's logical palette */
  965. extern unsigned char far win_dacbox[256][3];
  966. #define PALETTESIZE 256           /* dull-normal VGA            */
  967.  
  968. static int win_fsteps[] = {54, 24, 8};
  969.  
  970. int win_animate_flag = 0;
  971. int win_syscolorindex[21];
  972. DWORD win_syscolorold[21];
  973. DWORD win_syscolornew[21];
  974.  
  975. extern int debugflag;
  976.  
  977. win_cycle()
  978. {
  979. int istep, jstep, fstep, step, oldstep, last, next, maxreg;
  980. int incr, fromred, fromblue, fromgreen, tored, toblue, togreen;
  981. HDC hDC;              /* handle to device context        */
  982.  
  983. fstep = 1;                /* randomization frequency    */
  984. oldstep = 1;                /* single-step            */
  985. step = 256;                /* single-step            */
  986. incr = 999;                /* ready to randomize        */
  987. maxreg = 256;                /* maximum register to rotate    */
  988. last = maxreg-1;            /* last box that was filled    */
  989. next = 1;                /* next box to be filled    */
  990. if (win_cycledir < 0) {
  991.     last = 1;
  992.     next = maxreg;
  993.     }
  994. srand((unsigned)time(NULL));        /* randomize things        */
  995.  
  996. hDC = GetDC(GetFocus());
  997.  
  998. win_animate_flag = 1;
  999. SetPaletteEntries(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  1000. SelectPalette (hDC, hPal, 1);
  1001.  
  1002. if ((iNumColors == 16 || debugflag == 1000) && !win_systempaletteused) {
  1003.     int i;
  1004.     DWORD white, black;
  1005.     win_systempaletteused = TRUE;
  1006.     white = 0xffffff00;
  1007.     black = 0;
  1008.     for (i = 0; i <= COLOR_ENDCOLORS; i++) {
  1009.     win_syscolorindex[i] = i;
  1010.     win_syscolorold[i] = GetSysColor(i);
  1011.     win_syscolornew[i] = black;
  1012.     }
  1013.     win_syscolornew[COLOR_BTNTEXT] = white;
  1014.     win_syscolornew[COLOR_CAPTIONTEXT] = white;
  1015.     win_syscolornew[COLOR_GRAYTEXT] = white;
  1016.     win_syscolornew[COLOR_HIGHLIGHTTEXT] = white;
  1017.     win_syscolornew[COLOR_MENUTEXT] = white;
  1018.     win_syscolornew[COLOR_WINDOWTEXT] = white;
  1019.     win_syscolornew[COLOR_WINDOWFRAME] = white;
  1020.     win_syscolornew[COLOR_INACTIVECAPTION] = white;
  1021.     win_syscolornew[COLOR_INACTIVEBORDER] = white;
  1022.     SetSysColors(COLOR_ENDCOLORS,(LPINT)win_syscolorindex,(LONG FAR *)win_syscolornew);
  1023.     SetSystemPaletteUse(hDC,SYSPAL_NOSTATIC);
  1024.     UnrealizeObject(hPal);
  1025.     }
  1026.  
  1027. while (time_to_cycle) {
  1028.     if (win_cyclerand) {
  1029.     for (istep = 0; istep < step; istep++) {
  1030.         jstep = next + (istep * win_cycledir);
  1031.         if (jstep <=      0) jstep += maxreg-1;
  1032.         if (jstep >= maxreg) jstep -= maxreg-1;
  1033.         if (++incr > fstep) {    /* time to randomize    */
  1034.         incr = 1;
  1035.         fstep = ((win_fsteps[win_cyclefreq]*
  1036.             (rand() >> 8)) >> 6) + 1;
  1037.         fromred   = dacbox[last][0];
  1038.         fromgreen = dacbox[last][1];
  1039.         fromblue  = dacbox[last][2];
  1040.         tored      = rand() >> 9;
  1041.         togreen   = rand() >> 9;
  1042.         toblue      = rand() >> 9;
  1043.         }
  1044.         dacbox[jstep][0] = fromred     + (((tored   - fromred  )*incr)/fstep);
  1045.         dacbox[jstep][1] = fromgreen + (((togreen - fromgreen)*incr)/fstep);
  1046.         dacbox[jstep][2] = fromblue  + (((toblue  - fromblue )*incr)/fstep);
  1047.         }
  1048.     }
  1049.     if (step >= 256) step = oldstep;
  1050.  
  1051.     spindac(win_cycledir,step);
  1052.     AnimatePalette(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  1053.     RealizePalette(hDC);
  1054.     keypressed();
  1055.     if (win_cyclerand == 2) {
  1056.     win_cyclerand = 1;
  1057.     step = 256;
  1058.     }
  1059.     }
  1060.  
  1061. win_animate_flag = 0;
  1062. ReleaseDC(GetFocus(),hDC);
  1063.  
  1064. }
  1065.  
  1066. /* cursor routines */
  1067.  
  1068. extern HANDLE hSaveCursor;           /* the original cursor value */
  1069. extern HANDLE hHourGlass;           /* the hourglass cursor value */
  1070.  
  1071. start_wait()
  1072. {
  1073.    hSaveCursor = SetClassWord(hwnd, GCW_HCURSOR, hHourGlass);
  1074. }
  1075.  
  1076. end_wait()
  1077. {
  1078.    SetClassWord(hwnd, GCW_HCURSOR, hSaveCursor);
  1079. }
  1080.  
  1081. /* video-mode routines */
  1082.  
  1083. extern int    viewwindow;        /* 0 for full screen, 1 for window */
  1084. extern float  viewreduction;        /* window auto-sizing */
  1085. extern float  finalaspectratio;     /* for view shape and rotation */
  1086. extern int    viewxdots,viewydots;    /* explicit view sizing */
  1087. extern int    fileydots, filexdots, filecolors;
  1088. extern float  fileaspectratio;
  1089. extern int    skipxdots,skipydots;    /* for decoder, when reducing image */
  1090.  
  1091. int get_video_mode(struct fractal_info *info)
  1092. {
  1093.    viewwindow = viewxdots = viewydots = 0;
  1094.    fileaspectratio = .75;
  1095.    skipxdots = skipydots = 0;
  1096.    return(0);
  1097. }
  1098.  
  1099.  
  1100. void spindac(int direction, int step)
  1101. {
  1102. int i, j, k;
  1103.  
  1104. for (k = 0; k < step; k++) {
  1105.     if (direction > 0) {
  1106.     for (j = 0; j < 3; j++) {
  1107.         for (i = 255; i >= 1; i--)
  1108.         dacbox[i+1][j] = dacbox[i][j];
  1109.         dacbox[1][j] = dacbox[256][j];
  1110.         }
  1111.     }
  1112.     if (direction < 0) {
  1113.     for (j = 0; j < 3; j++) {
  1114.         dacbox[256][j] = dacbox[1][j];
  1115.         for (i = 1; i < 256; i++)
  1116.         dacbox[i][j] = dacbox[i+1][j];
  1117.         }
  1118.     }
  1119.     }
  1120.  
  1121.     /* fill in intensities for all palette entry colors */
  1122.     for (i = 0; i < 256; i++) {
  1123.     pLogPal->palPalEntry[i].peRed    = ((BYTE)dacbox[i][0]) << 2;
  1124.     pLogPal->palPalEntry[i].peGreen = ((BYTE)dacbox[i][1]) << 2;
  1125.     pLogPal->palPalEntry[i].peBlue    = ((BYTE)dacbox[i][2]) << 2;
  1126.     pLogPal->palPalEntry[i].peFlags = PC_RESERVED;
  1127.     }
  1128.  
  1129.     if (!win_animate_flag) {
  1130.     HDC hDC;
  1131.     hDC = GetDC(GetFocus());
  1132.     SetPaletteEntries(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  1133.     SelectPalette (hDC, hPal, 1);
  1134.     RealizePalette(hDC);
  1135.     ReleaseDC(GetFocus(),hDC);
  1136.         /* for non-palette-based adapters, redraw the image */
  1137.     if (!iRasterCaps)
  1138.             InvalidateRect(hwnd, NULL, FALSE);
  1139.     }
  1140. }
  1141.  
  1142. restoredac()
  1143. {
  1144. int iLoop;
  1145. int j;
  1146.  
  1147.     /* fill in intensities for all palette entry colors */
  1148.     for (iLoop = 0; iLoop < PALETTESIZE; iLoop++)
  1149.     for (j = 0; j < 3; j++)
  1150.         dacbox[iLoop][j] = win_dacbox[iLoop][j];
  1151.     spindac(0,1);
  1152. }
  1153.  
  1154. int ValidateLuts( char * fn )
  1155. {
  1156. FILE * f;
  1157. unsigned    r, g, b, index;
  1158. unsigned char    line[101];
  1159. unsigned char    temp[81];
  1160.     strcpy (temp,fn);
  1161.     if (strchr(temp,'.') == NULL) /* Did name have an extension? */
  1162.         strcat(temp,".map");  /* No? Then add .map */
  1163.     findpath( temp, line);          /* search the dos path */
  1164.     f = fopen( line, "r" );
  1165.     if (f == NULL)
  1166.         return 1;
  1167.     for( index = 0; index < 256; index++ ) {
  1168.         if (fgets(line,100,f) == NULL)
  1169.             break;
  1170.         sscanf( line, "%d %d %d", &r, &g, &b );
  1171.         /** load global dac values **/
  1172.         dacbox[index][0] = r >> 2;    /* maps default to 8 bits */
  1173.         dacbox[index][1] = g >> 2;    /* DAC wants 6 bits */
  1174.         dacbox[index][2] = b >> 2;
  1175.     }
  1176.     fclose( f );
  1177.     return 0;
  1178. }
  1179.  
  1180. int win_thinking = 0;
  1181.  
  1182. int thinking(int waiting, char *dummy)
  1183. {
  1184. if (waiting && ! win_thinking) {
  1185.     win_thinking = 1;
  1186.     start_wait();
  1187.     }
  1188. if (!waiting)
  1189.     end_wait();
  1190. return(keypressed());
  1191. }
  1192.  
  1193. int far_strlen(char far *string) {
  1194. int i;
  1195. for (i = 0; ; i++)
  1196.     if (string[i] == 0)
  1197.     return(i);
  1198. }
  1199.  
  1200. int far_strnicmp(char far *string1, char far *string2, int maxlen) {
  1201. int i;
  1202. unsigned char j, k;
  1203. for (i = 0;i < maxlen ; i++) {
  1204.     j = string1[i];
  1205.     k = string2[i];
  1206.     if (j >= 'a' && j <= 'z') j -= ('a' - 'A');
  1207.     if (k >= 'a' && k <= 'z') k -= ('a' - 'A');
  1208.     if (j-k != 0)
  1209.     return(j-k);
  1210.     }
  1211. return(0);
  1212. }
  1213.  
  1214. int far_memcpy(void far *string1, void far *string2, int maxlen) {
  1215. int i;
  1216. for (i = 0;i < maxlen ; i++)
  1217.     ((char far *)string1)[i] = ((char far *)string2)[i];
  1218. }
  1219.  
  1220. /* fake/not-yet-implemented subroutines */
  1221.  
  1222. int getakeynohelp() {return(getakey());}
  1223.  
  1224. void farmessage(unsigned char far *foo) {}
  1225. void setvideomode(int foo1, int foo2, int foo3, int foo4) {}
  1226. int fromvideotable() {}
  1227. int setforgraphics() {}
  1228. int setfortext() {}
  1229. int movecursor() {}
  1230. int home() {}
  1231.  
  1232. int intro_overlay() {}
  1233. int help_overlay() {}
  1234. int prompts_overlay() {}
  1235. int rotate_overlay() {}
  1236. int printer_overlay() {}
  1237. int miscovl_overlay() {}
  1238. int pot_startdisk() {}
  1239. int SetTgaColors() {}
  1240. int startdisk() {}
  1241. int enddisk() {}
  1242. int readdisk() {}
  1243. int writedisk() {}
  1244. int nosnd(){}
  1245. int snd(){}
  1246. int targa_startdisk(){}
  1247. int targa_writedisk(){}
  1248. int SetColorPaletteName() {}
  1249. int get_3d_params() { return(0);}
  1250. int findfont() {return(0);}
  1251. int readticker(){return(0);}
  1252. int EndTGA(){}
  1253.  
  1254. int setattr(){}
  1255. int helptitle(){}
  1256. int stackscreen(){}
  1257. int unstackscreen(){}
  1258. void putstring(int foo1, int foo2, int foo3, unsigned char far *foo4){}
  1259. int putstringcenter(int foo1, int foo2, int foo3, int foo4, char far *foo5){}
  1260. int dvid_status(){}
  1261. int goodbye(){}
  1262. int tovideotable(){}
  1263.  
  1264. void load_mat(){}
  1265. void mult_vec_iit(){}
  1266. int check_vidmode_keyname(){return(0);}
  1267. void print_document(){}
  1268. void makedoc_msg_func(){}
  1269.  
  1270. void TranspPerPixel(){}
  1271.